package com.rf.richfitwheel.admin.conf;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.apache.shiro.web.filter.InvalidRequestFilter;
import org.apache.shiro.web.filter.mgt.FilterChainManager;
import org.apache.shiro.web.filter.mgt.PathMatchingFilterChainResolver;
import org.apache.shiro.web.servlet.AbstractShiroFilter;

import javax.servlet.Filter;

public class PluginShiroFilterFactoryBean extends ShiroFilterFactoryBean {

    @Override
    protected AbstractShiroFilter createInstance() throws Exception {
        AbstractShiroFilter shiroFilter = super.createInstance();
        PathMatchingFilterChainResolver filterChainResolver = (PathMatchingFilterChainResolver) shiroFilter.getFilterChainResolver();
        FilterChainManager filterChainManager = filterChainResolver.getFilterChainManager();
        Filter invalidRequestFilter = filterChainManager.getFilters().get("invalidRequest");
        if (invalidRequestFilter instanceof InvalidRequestFilter) {
            ((InvalidRequestFilter)invalidRequestFilter).setBlockNonAscii(false);
        }
        return shiroFilter;
    }
}
